import java.util.Arrays;

public class Solution1051 {
    public int heightChecker(int[] heights) {
        int[] b= Arrays.copyOf(heights,heights.length);
        Arrays.sort(b);
        int ans=0;
        for (int i=0;i<heights.length;i++){
            if (heights[i]!=b[i]){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1051().heightChecker(new int[]{1,1,4,2,1,3}));
    }
}
